#include <curses.h>
#include <ts7200.h>
#include <io.h>
#include <user.h>

void SetCursorXY(int x, int y) {
  Printf( COM2, "\x1b[%d;%dH", y, x );
}

void MoveCursorXY(int dx, int dy) { 
  if (dx < 0) {
    Printf( COM2, "\x1b[%dD", -dx ); 
  } else if (dx > 0) {
    Printf( COM2, "\x1b[%dC", dx );
  }
  if (dy < 0) {
    Printf( COM2, "\x1b[%dA", -dy );
  } else if (dy > 0) {
    Printf( COM2, "\x1b[%dB", dy );
  }
}   

void SetScreenColor(int fg, int bg) {
  Printf( COM2, "\x1b[%d;%dm", fg, bg );
}

void ClearLine() {
  Printf( COM2, "\x1b[2K" );
}

void ClearDown() {
  Printf( COM2, "\x1b[J" );
}

void ClearScreen() {
  Printf( COM2, "\x1b[2J" );
}

void SaveCursor() {
  Putc( COM2, '\x1b' );
  Putc( COM2, '7' );
}

void LoadCursor() {
  Putc( COM2, '\x1b' );
  Putc( COM2, '8' );
}
